﻿<script>
    window.fbAsyncInit = function () {
        FB.init({
            appId: '494855570579929', // App ID
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true  // parse XFBML
        });

        // Additional initialization code here
    };

    // Load the SDK Asynchronously
    (function (d) {
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) { return; }
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    } (document));
</script>

<script>
    $(function () {

        $('#btnLogin').click(function () {

            FB.login(function (response) {
                if (response.authResponse) {
                    debugger;
                    //console.log('Welcome!  Fetching your information.... ');
                    FB.api('/me', function (response) {
                        //console.log('Good to see you, ' + response.name + '.');
                    });
                } else {
                    //console.log('User cancelled login or did not fully authorize.');
                }
            }, { scope: 'email,user_likes,publish_stream' });

        });

        $('#btnPost').click(function () {

            $.ajax({
                url: '@Url.Action("PostearFB", "Demo")',
                type: "POST",
                dataType: "json",
                data: null,
                success: function (data) {
                    alert("Se Grabo Correctamente!");
                }
            })

        });

        $('#btnPostComentario').click(function () {

            $.ajax({
                url: '@Url.Action("PostearComentario", "Demo")',
                type: "POST",
                dataType: "json",
                data: null,
                success: function (data) {
                    alert("Se Grabo Correctamente!");
                }
            })

        });

    });
</script>


@{
        ViewBag.Title = "Login";
        string oauthUrl = Chillis.CRM.Web.Constants.GetFacebookLoginUrl(Request["returnUrl"]);
    }


<h1>
    Hola!</h1>

<div id="fb-root"></div>
  
<h2>
        Login Using Facebook</h2>
    <div style="margin: 10px auto">
        <a href="@oauthUrl">
            <img title="Login With Facebook" alt="Login With Facebook" src="/images/loginwithfb.png" /></a>
    </div>

    <button id="btnLogin">Login</button>

    <button id="btnPost">Registra Post</button>

    <button id="btnPostComentario">Registra Comentario</button>